interface IPerson {
  name: string;
  age: number;
  height: number;
}
const p: IPerson = {
  name: 'literal-name',
  age: 18,
  height: 1.88,
}
// 1.索引签名的理解
interface IInfo {
  // 索引签名: 可以通过字符串索引, 去获取到一个值, 也是字符串
  [key: string]: string
}

function getInfo(): IInfo {
  const name: any = "literal-key"
  return name
}
const info = getInfo()
const name = info["name"]
console.log(name, info.age, info.address)

// 2.索引签名的案例
interface ICollection {
  [index: number]: string
  length: number
}

function printCollection(collection: ICollection) {
  for (let i = 0; i < collection.length; i++) {
    const item = collection[i]
    console.log(item, item.length)
  }
}

const array = ["a", "b", "c"]
const tuple: [string, string] = ["aaa", "bb"]
printCollection(array)
printCollection(tuple)

export {};